package com.test.learnkotlin.generics

import java.lang.reflect.ParameterizedType

open class BaseUser<ANMIAL : Animal>(val name: String? = "") {

    open val mAnimal: ANMIAL by lazy {
        val type: Class<ANMIAL> =
            (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<ANMIAL>
        type?.let {
            it.newInstance()
        }
    }

    open fun setAnimalInfo(parmName: String? = "", parmAge: Int = 0) {
        mAnimal?.apply {
            name = parmName
            age = parmAge
        }
    }

    open fun printAnimalInfo() {
        mAnimal?.apply {
            println("宠物名：$name, 岁数：$age")
        }
    }

}